<?php
class ServiceController extends Controller {
	
	/**
	 * 信息输入
	 * Enter description here ...
	 */
	function InputAction()
	{
		$this->view("service.input","item");
	}
	
	/**
	 * 顾客回访
	 * Enter description here ...
	 */
	function ReturnAction(){
		$this->view("service.return","item");
	}
	
	/**
	 * 顾客回访
	 * Enter description here ...
	 */
	function ReturnListAction(){
		$p["p"] = P("pageIndex",0);
		$p["r"] = P("pageSize",15);
		$p["name"] = P("name","");
		$p["statusFlg"] = "";
		$status = P("statusFlg","");
		if($status == "2"){
			$p["statusFlg"] = "not";
		}
		$p["sortField"] = P("sortField","id");
		$p["sortOrder"] = P("sortOrder","asc");
		$p["start"] = $p["r"]*$p["p"];
		$p["end"] = $p["r"];

		$data = FeedbackModel::getInstance()->FeedbackList($p);
		$this->json->toJson(array("total"=>FeedbackModel::getInstance()->FeedbackCount($p),"data"=>$data));
	}
	
	/**
	 * 保存回访数据
	 * Enter description here ...
	 */
	function ReturnSaveAction(){
		$p["id"] = P("id","0");
		$p["returnNum"] = P("returnNum","");
		$p["returnCon1"] = P("returnCon1","");
		$p["returnCon2"] = P("returnCon2","");
		if($p["id"] != 0){
			FeedbackModel::getInstance()->FeedbackAdd($p);
		}
		$this->json->code("OK")->out();
	}
	
	/**
	 * 保存投诉
	 * Enter description here ...
	 */
	function InputSaveOneAction()
	{
		$p["customs_id"] = P("customs_id1","0");
		$p["contact"] = P("contact1","");
		$p["types"] = P("types","0");
		$p["agency_id"] = P("agency_id","0");
		$p["title"] = P("title1","");
		$p["content"] = P("content1","");
		$p["input_staff"] = $this->user["cid"];
		
		ComplaintsModel::getInstance()->Save($p);
		
		//业务进度日志
		//$staff = StaffModel::getInstance()->getStaffByName($p['con_staff_id']);
		//$param[3]=$staff;
		//$this->BLog(BLogType::STAFF, $p['con_staff_id'],$p['id']);
		//$this->BSLog(BLogType::STAFF,0,$p['id'],$param);
		$this->json->code("OK")->out();
	}
	
	/**
	 * 咨询（顾客）
	 * Enter description here ...
	 */
	function InputSaveTwoAction()
	{
		$p["user"]=P("login","");
		$p["name"]=P("name","");
		$p["mobile_phone"]=P("mobile","");
		$p["tel"]=P("tel","");
		$p["email"]=P("email","");
		$p["qq"]=P("qq","");
		
		$rs = FrameworkModel::getInstance()->getUserByName($p["user"]);
		if(isset($rs["id"])){
			$this->json->code("MG")->msg("登录名已经存在了！")->out();
			return;
		}
		$p1["name"]=P("name","");
		$rs = CustomerModel::getInstance()->getCustomerByName($p1);
		if(isset($rs["id"])){
			$this->json->code("MG")->msg("名称已经存在了！")->out();
			return;
		}
		$rs = CustomerModel::getInstance()->setUsersAdd($p);
		if($rs<=0){
			$this->json->code("MG")->msg("操作失败！")->out();
			return;
		}
		$p["login"]=$rs;
		$rs = CustomerModel::getInstance()->setCustomerAdd($p);
		if($rs<=0){
			$p2["id"]=$p["login"];
			FrameworkModel::getInstance()->setUsersDel($p2);
			$this->json->code("MG")->msg("操作失败！")->out();
			return;
		}
		
		$p3["types"] = 2;
		$p3["customs_id"] = $rs;
		$p3["content"] = P("content2","");
		$p3["contact"] = "";
		$p3["title"] = "";
		$p3["agency_id"] = 0;
		$p3["input_staff"] = $this->user["id"];
		
		ComplaintsModel::getInstance()->Save($p3);
		
		$this->json->code("OK")->out();
	}
	
	// 取得客服输入信息
	function ComplsintsAction(){
		$p["p"] = P("pageIndex",0);
		$p["r"] = P("pageSize",15);
		$p["title"] = P("title","");
		$p["sortField"] = P("sortField","id");
		$p["sortOrder"] = P("sortOrder","asc");
		$p["start"] = $p["r"]*$p["p"];
		$p["end"] = $p["r"];
		
		$data = ComplaintsModel::getInstance()->getComplaints($p);
		$this->json->toJson(array("total"=>ComplaintsModel::getInstance()->getCount($p),"data"=>$data));
	}
	
	// 取得客服输入信息
	function ComplsintsTwoAction(){
		$p["p"] = P("pageIndex",0);
		$p["r"] = P("pageSize",15);
		$p["types"] = P("types","");
		$p["status"] = P("status","");
		$p["title"] = P("title","");
		$agency_id = P("agency_id","");
		$updated1 = P("updated1","");
		$updated2 = P("updated2","");
		
		$p["sortField"] = P("sortField","id");
		$p["sortOrder"] = P("sortOrder","asc");
		$p["start"] = $p["r"]*$p["p"];
		$p["end"] = $p["r"];
		
		if($updated1 != ""){
			$p["updated1"]=DateTool::intToDateTime(strtotime($updated1)-3600*8);
		}else{
			$p["updated1"]="";
		}
		
		if($updated2 != ""){
			$p["updated2"]=DateTool::intToDateTime(strtotime($updated2)-3600*8);
		}else{
			$p["updated2"]="";
		}
		
		$agency = CommonModel::getInstance()->getAgencyAllList();
		$p["agency_id"] = ArrayTool::ArrayToIDs($agency,$agency_id);
		
		
		$data = ComplaintsModel::getInstance()->getComplaints($p);
		$this->json->toJson(array("total"=>ComplaintsModel::getInstance()->getCount($p),"data"=>$data));
	}
	
	//业务申报
	function DeclareAction(){
		$this->view("service.declare","item");
	}
	
	function DeclareSaveAction(){
		$p["types"] = P("types","1");
		$p["customs_id"] = P("customs_id","0");
		$p["title"] = P("title","");
		$p["content"] = P("content","");
		$p["business_staff_id"] = $this->user["cid"];
		BusinessModel::getInstance()->DeclareSave($p);
		$this->json->code("OK")->out();
	}
	
	//工单查询
	function SelectAction(){
		$b["cid"]=$this->user["cid"];
		$types = BusinessModel::getInstance()->StaffBybusiness($b);
		if(isset($types) && $types != ""){
			$this->JS["types"] = $types;
		}else{
			$this->JS["types"] = " ";
		}
		$this->view("service.select","item");
	}
}